﻿using System.Runtime.InteropServices;

namespace WindowsAPI.PE
{
    [StructLayout(LayoutKind.Explicit, Pack = 1)]
    public struct IMAGE_OPTIONAL_HEADER32
    {
        [FieldOffset(0)]
        public readonly MagicType Magic;

        [FieldOffset(2)]
        public readonly byte MajorLinkerVersion;

        [FieldOffset(3)]
        public readonly byte MinorLinkerVersion;

        [FieldOffset(4)]
        public readonly uint SizeOfCode;

        [FieldOffset(8)]
        public readonly uint SizeOfInitializedData;

        [FieldOffset(12)]
        public readonly uint SizeOfUninitializedData;

        [FieldOffset(16)]
        public readonly uint AddressOfEntryPoint;

        [FieldOffset(20)]
        public readonly uint BaseOfCode;

        // PE32 contains this additional field
        [FieldOffset(24)]
        public readonly uint BaseOfData;

        [FieldOffset(28)]
        public readonly uint ImageBase;

        [FieldOffset(32)]
        public readonly uint SectionAlignment;

        [FieldOffset(36)]
        public readonly uint FileAlignment;

        [FieldOffset(40)]
        public readonly ushort MajorOperatingSystemVersion;

        [FieldOffset(42)]
        public readonly ushort MinorOperatingSystemVersion;

        [FieldOffset(44)]
        public readonly ushort MajorImageVersion;

        [FieldOffset(46)]
        public readonly ushort MinorImageVersion;

        [FieldOffset(48)]
        public readonly ushort MajorSubsystemVersion;

        [FieldOffset(50)]
        public readonly ushort MinorSubsystemVersion;

        [FieldOffset(52)]
        public readonly uint Win32VersionValue;

        [FieldOffset(56)]
        public readonly uint SizeOfImage;

        [FieldOffset(60)]
        public readonly uint SizeOfHeaders;

        [FieldOffset(64)]
        public readonly uint CheckSum;

        [FieldOffset(68)]
        public readonly SubSystemType Subsystem;

        [FieldOffset(70)]
        public readonly DllCharacteristicsType DllCharacteristics;

        [FieldOffset(72)]
        public readonly uint SizeOfStackReserve;

        [FieldOffset(76)]
        public readonly uint SizeOfStackCommit;

        [FieldOffset(80)]
        public readonly uint SizeOfHeapReserve;

        [FieldOffset(84)]
        public readonly uint SizeOfHeapCommit;

        [FieldOffset(88)]
        public readonly uint LoaderFlags;

        [FieldOffset(92)]
        public readonly uint NumberOfRvaAndSizes;

        //[FieldOffset(96)]
        //public readonly Data_Directory ExportTable;

        //[FieldOffset(104)]
        //public readonly Data_Directory ImportTable;

        //[FieldOffset(112)]
        //public readonly Data_Directory ResourceTable;

        //[FieldOffset(120)]
        //public readonly Data_Directory ExceptionTable;

        //[FieldOffset(128)]
        //public readonly Data_Directory CertificateTable;

        //[FieldOffset(136)]
        //public readonly Data_Directory BaseRelocationTable;

        //[FieldOffset(144)]
        //public readonly Data_Directory Debug;

        //[FieldOffset(152)]
        //public readonly Data_Directory Architecture;

        //[FieldOffset(160)]
        //public readonly Data_Directory GlobalPtr;

        //[FieldOffset(168)]
        //public readonly Data_Directory TLSTable;

        //[FieldOffset(176)]
        //public readonly Data_Directory LoadConfigTable;

        //[FieldOffset(184)]
        //public readonly Data_Directory BoundImport;

        //[FieldOffset(192)]
        //public readonly Data_Directory IAT;

        //[FieldOffset(200)]
        //public readonly Data_Directory DelayImportDescriptor;

        //[FieldOffset(208)]
        //public readonly Data_Directory CLRRuntimeHeader;

        //[FieldOffset(216)]
        //public readonly Data_Directory Reserved;
    }
}
